<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Strict//EN"
"http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd">
<html xmlns="http://www.w3.org/1999/xhtml" xml:lang="en" lang="en">
<head>
  <link rel="stylesheet" href="stylesheets/screen.css" type="text/css" media="screen" />
  <meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
  <title>
      polyglot
  </title>
  <script src="javascripts/rounded_corners_lite.inc.js" type="text/javascript"></script>
<style>

</style>
  <script type="text/javascript">
    window.onload = function() {
      settings = {
          tl: { radius: 10 },
          tr: { radius: 10 },
          bl: { radius: 10 },
          br: { radius: 10 },
          antiAlias: true,
          autoPad: true,
          validTags: ["div"]
      }
      var versionBox = new curvyCorners(settings, document.getElementById("version"));
      versionBox.applyCornersToAll();
    }
  </script>
</head>
<body>
<div id="main">

    <h1>polyglot</h1>
    <div id="version" class="clickable" onclick='document.location = "http://rubyforge.org/projects/polyglot"; return false'>
      <p>Get Version</p>
      <a href="http://rubyforge.org/projects/polyglot" class="numbers">0.3.2</a>
    </div>
    <h2>Poly =&gt; many, glot =&gt; languages</h2>
<h2>What</h2>
<p>Polyglot provides a registry of file types that can be loaded by<br />
calling its improved version of &#8216;require&#8217;. Each file extension<br />
that can be handled by a custom loader is registered by calling<br />
Polyglot.register(&#8220;ext&#8221;, &lt;class&gt;), and then you can simply<br />
require &#8220;somefile&#8221;, which will find and load &#8220;somefile.ext&#8221;<br />
using your custom loader.</p>
<p>This supports the creation of DSLs having a syntax that is most<br />
appropriate to their purpose, instead of abusing the Ruby syntax.</p>
<p>Required files are attempted first using the normal Ruby loader,<br />
and if that fails, Polyglot conducts a search for a file having<br />
a supported extension.</p>
<h2>Installing</h2>
<p><pre class='syntax'><span class="ident">sudo</span> <span class="ident">gem</span> <span class="ident">install</span> <span class="ident">polyglot</span></pre></p>
<h2>Example</h2>
<p>Define and register your file type loader in file rubyglot.rb:</p>
<pre>    require 'polyglot'
    class RubyglotLoader
        def self.load(filename, options = nil, &amp;block)
            File.open(filename) {|file|
                # Load the contents of file as Ruby code:
                # Implement your parser here instead!
                Kernel.eval(file.read)
            }
        end
    end
    Polyglot.register("rgl", RubyglotLoader)
</pre>
<p>This file, hello.rgl, will be loaded (this simple example uses Ruby code):</p>
<pre>    puts "Initializing"
    class Hello
        def initialize()
            puts "Hello, world\n"
        end
    end
</pre>
<p>Call it from file test.rb:</p>
<pre>    require 'rubyglot'	# Create my file type handler
    require 'hello'	# Can add extra options or even a block here
    puts "Ready to go"
    Hello.new
</pre>
<p>Run:</p>
<pre>    $ ruby test.rb
    Initializing
    Ready to go
    Hello, world
    $
</pre>
<h2>How to submit patches</h2>
<p>Read the <a href="http://drnicwilliams.com/2007/06/01/8-steps-for-fixing-other-peoples-code/">8 steps for fixing other people&#8217;s code</a> and for section <a href="http://drnicwilliams.com/2007/06/01/8-steps-for-fixing-other-peoples-code/#8z-email">8z: Submit patch</a>, email me on the link below.</p>
<p>The trunk repository is <code>http://github.com/cjheath/polyglot</code>.</p>
<h2>License</h2>
<p>This code is free to use under the terms of the <span class="caps">MIT</span> license.</p>
<h2>Contact</h2>
<p>Comments are welcome. Send an email to <a href="http://github.com/cjheath">Clifford Heath</a></p>
    <p class="coda">
      <a href="cjheath@rubyforge.org">Clifford Heath</a>, 15th June 2010<br>
      Theme extended from <a href="http://rb2js.rubyforge.org/">Paul Battley</a>
    </p>
</div>

<!-- insert site tracking codes here, like Google Urchin -->

</body>
</html>
